package com.jk.dailydemo;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jk.dailydemo.screenShot.ScreenShot;
import com.jk.dailydemo.theme.Theme;

import java.util.List;

/**
 * Created by Administrator on 2017/5/28.
 */

public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder>{
    private List<String> mDatas;
    private Context mContext;
    public MainAdapter(List<String> mDatas) {
        this.mDatas = mDatas;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        mContext  = parent.getContext();
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.item_main_view, parent, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        String itemTitle = mDatas.get(position);
        holder.mTvItemTitle.setText(itemTitle);

        holder.mTvItemTitle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onItemClickListen.onItemClickListen(v,holder,position);
            }
        });

        if (position%2 == 0){
            holder.mLlMainItemContainer.setBackgroundColor(mContext.getColor(R.color.colorGrey300));
        }else{
            holder.mLlMainItemContainer.setBackgroundColor(mContext.getColor(R.color.colorLightBlue300));
        }


    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        private TextView mTvItemTitle;
        private LinearLayout mLlMainItemContainer;

        public ViewHolder(View itemView) {
            super(itemView);
            mTvItemTitle = (TextView) itemView.findViewById(R.id.tv_item_title);
            mLlMainItemContainer = (LinearLayout) itemView.findViewById(R.id.ll_main_item_container);
        }
    }

    private OnItemClickListen onItemClickListen;
    public interface OnItemClickListen{
        void onItemClickListen(View v,ViewHolder holder, int position);
    }

    public void setOnItemClickListen(OnItemClickListen onItemClickListen){
        this.onItemClickListen = onItemClickListen;
    }





}
